package com.iias.communication.message.server;

import com.iias.common.util.log.LogUtils;
import com.iias.communication.consts.CommunicationConst;
import com.iias.communication.domain.DecodeInfo;
import com.iias.communication.packet.ProPacket;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import org.slf4j.Logger;

import java.util.List;

/**
 * 解码器
 */
public class ServerFilterDecoder extends ByteToMessageDecoder {

    private final static Logger log = LogUtils.getLogger();


    public void decode(ChannelHandlerContext ctx, ByteBuf byteBuf , List<Object> out){
        byte[] req = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(req);
        DecodeInfo decodeInfo = CommunicationConst.PROTOCOL.getDecode().decodeInfo(req);
        if (decodeInfo == null) return;
//        int end = decodeInfo.getEnd();
//        if (end>0)byteBuf.skipBytes(end);
//        byteBuf.skipBytes(byteBuf.readableBytes());
        List<ProPacket> objects = decodeInfo.getObjects();
        if (objects!=null && objects.size()>0)out.addAll(objects);
        return;
    }


}